package com.example.ndkjnidemo.home;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.example.ndkjnidemo.R;
import com.example.ndkjnidemo.databinding.FragmentHomeBinding;
import com.example.ndkjnidemo.home.arraycopy.ArrayCopyActivity;
import com.example.ndkjnidemo.home.arraylist.ArraylistActivity;
import com.example.ndkjnidemo.home.basetype.BaseTypeActivity;
import com.example.ndkjnidemo.home.crash.CrashActivity;
import com.example.ndkjnidemo.home.dynamicregist.DynamicRegistActivity;
import com.example.ndkjnidemo.home.exception.Exception2Activity;
import com.example.ndkjnidemo.home.exception.ExceptionActivity;
import com.example.ndkjnidemo.home.methodfield.MethodFieldActivity;
import com.example.ndkjnidemo.home.reference.RefActivity;
import com.example.ndkjnidemo.home.staticregist.StaticRegistActivity;
import com.example.ndkjnidemo.home.threadcallback.ThreadCallbackActivity;


public class HomeFragment extends Fragment implements View.OnClickListener {

    private HomeViewModel homeViewModel;
    private FragmentHomeBinding binding;
    //===

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        //===
        homeViewModel =
                new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(HomeViewModel.class);
        //===
        binding = FragmentHomeBinding.inflate(inflater, container, false);
        View root = binding.getRoot();
        //===
        binding.btnDemo.setOnClickListener(this);
        binding.btnDynamicRegist.setOnClickListener(this);
        binding.btnThreadCallback.setOnClickListener(this);
        binding.btnException.setOnClickListener(this);
        binding.btnException2.setOnClickListener(this);
        binding.btnCrash.setOnClickListener(this);
        binding.btnRef.setOnClickListener(this);
        binding.btnJniJava.setOnClickListener(this);
        binding.btnBaseType.setOnClickListener(this);
        binding.btnArrayCopy.setOnClickListener(this);
        binding.btnArraylist.setOnClickListener(this);
        //===
        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_demo) {
            startActivity(new Intent(getActivity(), StaticRegistActivity.class));
        } else if (v.getId() == R.id.btn_dynamic_regist) {
            startActivity(new Intent(getActivity(), DynamicRegistActivity.class));
        } else if (v.getId() == R.id.btn_thread_callback) {
            startActivity(new Intent(getActivity(), ThreadCallbackActivity.class));
        } else if (v.getId() == R.id.btn_exception) {
            startActivity(new Intent(getActivity(), ExceptionActivity.class));
        } else if (v.getId() == R.id.btn_exception2) {
            startActivity(new Intent(getActivity(), Exception2Activity.class));
        } else if (v.getId() == R.id.btn_crash) {
            startActivity(new Intent(getActivity(), CrashActivity.class));
        } else if (v.getId() == R.id.btn_ref) {
            startActivity(new Intent(getActivity(), RefActivity.class));
        } else if (v.getId() == R.id.btn_jni_java) {
            startActivity(new Intent(getActivity(), MethodFieldActivity.class));
        } else if (v.getId() == R.id.btn_base_type) {
            startActivity(new Intent(getActivity(), BaseTypeActivity.class));
        } else if (v.getId() == R.id.btn_array_copy) {
            startActivity(new Intent(getActivity(), ArrayCopyActivity.class));
        } else if (v.getId() == R.id.btn_arraylist) {
            startActivity(new Intent(getActivity(), ArraylistActivity.class));
        }
    }
}